import { ref } from 'vue'
import { defineStore } from 'pinia'

type userType = {
    username: string
    realname: string 
    createdAt: Date
}

const getItem =  localStorage.getItem('realname.id')
const info = JSON.parse(getItem || '{}')

export const useUsererStore = defineStore('user', () => {
  let userInfo = ref<userType | null>()
  if(!userInfo.value) {
    userInfo.value = info
  }
  function setUserInfo(data: userType) {
    userInfo.value = data
  }
  function removeUserInfo() {
    userInfo.value = null
  }

  return { userInfo, setUserInfo, removeUserInfo }
})
